#include <iostream>
#include <math.h>
#include <unordered_map>
using namespace std;

bool is_prime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(num); i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int words_to_number(string wordes) {
    unordered_map<string, int> b = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    string num_str = "";
    for (int i = 0; i < wordes.length(); i++) {
        if (wordes[i] != ' ') {
            num_str += to_string(b[wordes.substr(i, wordes.find(' ', i)-i)]);
            i = wordes.find(' ', i);
            if (i == string::npos) {
                break;
            }
        }
    }
    
    if (num_str.find_first_not_of("1234567890") != string::npos || num_str.length() != 3) {
        return -1;
    }
    
    return stoi(num_str);
}

int find_nearest_prime(int num) {
    if (is_prime(num)) {
        return num;
    }
    
    int low = num - 1;
    int up = num + 1;
    while (true) {
        if (is_prime(low)) {
            return low;
        }
        if (is_prime(up)) {
            return up;
        }
        low -= 1;
        up += 1;
    }
    return -1;
}

int main() {
    string wordes;
    getline(cin, wordes);
    int num = words_to_number(wordes);
    if (num == -1) {
        cout << "Wrong input" << endl;
    } else {
        int resultes = find_nearest_prime(num);
        cout << resultes << endl;
    }
    return 0;
}